% 使用有反聚类确定位置

X = 0:.1:10;
Y = sin(2*pi*.01.*X) + 1 .* sin(2*pi*.03.*X); % 高频的例子

markIdx = 2:4:length(X);
markCount = length(markIdx);

f = figure(1);
hold on;

plot(X, Y);

idxBias = 1;

options = optimoptions(@fmincon,'Algorithm','sqp','MaxIterations',4);

for i = 1:markCount
	idx = markIdx(i);
	xs = [X(idx-idxBias:idx-1) X(idx+1:idx+idxBias)];
	ys = [Y(idx-idxBias:idx-1) Y(idx+1:idx+idxBias)];
	x = X(idx);
	y = Y(idx);
	
	fun = @(V) 2 * norm(V-[x; y]) - norm(V-[xs(1); ys(1)]) - norm(V-[xs(end); ys(end)]);
	V0 = [x; y];
	V = fminunc(fun, V0, options);
	
	plot([x, V(1)], [y, V(2)], 'O');
end
